<?php
/**
 * Description of PersonFactory
 *
 * @author Gowork
 */
class Application_Model_PersonFactory {
    
    /**
     * Zwraca obiekt wskazanego profilu
     * @param int $iPersonType Application_Model_Person_Type
     * @param array $aOptions
     * @return \Application_Model_Person_Abstract
     * @throws Exception
     */
    public static function make($iPersonType,$aOptions = null) {
        
        if(!key_exists((int)$iPersonType, Application_Model_Person_Type::$T_aCodes)) {
            throw new Exception('Nie odnaleziono wskazanego typu profilu ('.$iPersonType.')');
        }
        
        $className = 'Application_Model_Person_'.ucfirst(Application_Model_Person_Type::$T_aCodes[$iPersonType]).'Person';
        
        if(!class_exists($className)) {
            throw new Exception('Nie odnaleziono klasy profilu '.$className);
        }
        
        /**
         * @var Application_Model_Person_Abstract
         */
        $oObject = new $className();
        $oObject->setId_type($iPersonType);
        
        if(is_array($aOptions)) {
            $oObject->setOptions($aOptions);
        }
        
        return $oObject;
    }
    
}

?>
